<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
	<title>Spring 3 MVC Series - Contact Manager</title>
	<style type="text/css">
		body {
			font-family: sans-serif;
		}
		.data, .data td {
			border-collapse: collapse;
			width: 100%;
			border: 1px solid #aaa;
			margin: 2px;
			padding: 2px;
		}
		.data th {
			font-weight: bold;
			background-color: #5c82ff;
			color: white;
		}
	</style>
</head>

<body>
	<h2>Contact Manager</h2>
	
	<form:form method="post" action="add.html" commandName="contact">
		<table>
			<tr>
				<td>
					<form:label path="firstName"><spring:message code="label.firstName"/></form:label>
				</td>
				<td>
					<form:input path="firstName"/>
				</td>
			</tr>
			<tr>
				<td>
					<form:label path="lastName"><spring:message code="label.lastName"/></form:label>
				</td>
				<td>
					<form:input path="lastName"/>
				</td>
			</tr>
			<tr>
				<td>
					<form:label path="email"><spring:message code="label.email"/></form:label>
				</td>
				<td>
					<form:input path="email"/>
				</td>
			</tr>
			<tr>
				<td>
					<form:label path="telephone"><spring:message code="label.telephone"/></form:label>
				</td>
				<td>
					<form:input path="telephone"/>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="submit" value="<spring:message code="label.addContact"/>"/>
				</td>
			</tr>
		</table>
	</form:form>
	
	<h3>Contacts</h3>
	<c:if test="${!empty contactList}">
		<table class="data">
			<tr>
				<th>Name</th>
				<th>Email</th>
				<th>Telephone</th>
				<th>&nbsp;</th>
			</tr>
			<c:forEach items="${contactList}" var="contact">
			<tr>
				<td>${contact.lastName}, ${contact.firstName}</td>
				<td>${contact.email}</td>
				<td>${contact.telephone}</td>
				<td><a href="delete/${contact.id}">delete</a></td>
			</tr>
			</c:forEach>
		</table>
	</c:if>
	
</body>

</html>